﻿using System;
using System.Xml;
using umbraco;

namespace BP.Umb.Logic
{
    public class Config
    {
        public const string SearchProvider_Membership = "membership";
        public const string SearchProvider_Examine = "examine";
        public const string SearchProvider_UmbracoNative = "umbraconative";
        protected string m_searchProvider;
        protected bool m_enablePaging;
        protected int m_pageSize;

        public string SearchProvider
        {
            get
            {
                return this.m_searchProvider;
            }
        }

        public bool EnablePaging
        {
            get
            {
                return this.m_enablePaging;
            }
        }

        public int PageSize
        {
            get
            {
                return this.m_pageSize;
            }
        }

        public Config()
        {
            this.m_searchProvider = "";
            this.m_enablePaging = true;
            this.m_pageSize = 20;
            new XmlDocument().PreserveWhitespace = true;
            XmlDocument xmlDocument = xmlHelper.OpenAsXmlDocument("/config/bpMemberAdmin.config");
            this.m_searchProvider = "";
            XmlNode xmlNode1 = xmlDocument.SelectSingleNode("//bpMemberAdminConfig");
            if (xmlNode1 == null)
                throw new Exception("bpMemberAdmin.config load error");
            if (!xmlNode1.HasChildNodes)
                return;
            foreach (XmlNode xmlNode2 in xmlNode1.SelectNodes("//SearchProvider"))
            {
                if (xmlNode2 != null && xmlNode2.Attributes["Type"] != null)
                    this.m_searchProvider = xmlNode2.Attributes["Type"].Value.ToLower();
            }
            foreach (XmlNode xmlNode2 in xmlNode1.SelectNodes("//DataGridPaging"))
            {
                if (xmlNode2 != null)
                {
                    if (xmlNode2.Attributes["EnablePaging"] != null)
                        this.m_enablePaging = xmlNode2.Attributes["EnablePaging"].Value.ToLower() == "true";
                    if (xmlNode2.Attributes["PageSize"] != null)
                        this.m_pageSize = Convert.ToInt32(xmlNode2.Attributes["PageSize"].Value);
                }
            }
        }
    }
}
